home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / basics / mfc simpleplayer.win / simpleplayermfcview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.8 KB  |  157 lines

  1. // SimplePlayer MFCView.cpp : implementation of the CSimplePlayerMFCView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SimplePlayerMFC.h"
  6.  
  7. #include "SimplePlayerMFCDoc.h"
  8. #include "SimplePlayerMFCView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CSimplePlayerMFCView
  18.  
  19. IMPLEMENT_DYNCREATE(CSimplePlayerMFCView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CSimplePlayerMFCView, CView)
  22.     //{{AFX_MSG_MAP(CSimplePlayerMFCView)
  23.     ON_WM_CREATE()
  24.     ON_WM_DESTROY()
  25.     ON_WM_SIZE()
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CSimplePlayerMFCView construction/destruction
  31.  
  32. CSimplePlayerMFCView::CSimplePlayerMFCView()
  33. {
  34.     // Create a QuickTime object
  35.     pQuickTime = new CQuickTime;
  36.  
  37. }
  38.  
  39. CSimplePlayerMFCView::~CSimplePlayerMFCView()
  40. {
  41.     // Destroy the QuickTime object
  42.     if ( pQuickTime ) 
  43.          delete pQuickTime;
  44. }
  45.  
  46. BOOL CSimplePlayerMFCView::PreCreateWindow(CREATESTRUCT& cs)
  47. {
  48.     // TODO: Modify the Window class or styles here by modifying
  49.     //  the CREATESTRUCT cs
  50.  
  51.     return CView::PreCreateWindow(cs);
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CSimplePlayerMFCView drawing
  56.  
  57. void CSimplePlayerMFCView::OnDraw(CDC* pDC)
  58. {
  59.     Movie    theMovie;
  60.     CSimplePlayerMFCDoc* pDoc = GetDocument();
  61.     ASSERT_VALID(pDoc);
  62.  
  63.     if (theMovie = pQuickTime->GetMovie())
  64.         UpdateMovie(theMovie);
  65. }
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CSimplePlayerMFCView diagnostics
  69.  
  70. #ifdef _DEBUG
  71. void CSimplePlayerMFCView::AssertValid() const
  72. {
  73.     CView::AssertValid();
  74. }
  75.  
  76. void CSimplePlayerMFCView::Dump(CDumpContext& dc) const
  77. {
  78.     CView::Dump(dc);
  79. }
  80.  
  81. CSimplePlayerMFCDoc* CSimplePlayerMFCView::GetDocument() // non-debug version is inline
  82. {
  83.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimplePlayerMFCDoc)));
  84.     return (CSimplePlayerMFCDoc*)m_pDocument;
  85. }
  86. #endif //_DEBUG
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CSimplePlayerMFCView message handlers
  90.  
  91. int CSimplePlayerMFCView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  92. {
  93.     if (CView::OnCreate(lpCreateStruct) == -1)
  94.         return -1;
  95.     
  96.     // Setup movie window     
  97.      strcpy((char *)pQuickTime->theAppName, AfxGetAppName());  // store app name for window title
  98.  
  99.     pQuickTime->OnMovieWindowCreate( m_hWnd, lpCreateStruct);
  100.     
  101.     return 0;
  102. }
  103.  
  104. void CSimplePlayerMFCView::OnDestroy() 
  105. {
  106.     CView::OnDestroy();
  107.     
  108.     // Destroy movie window
  109.     pQuickTime->OnMovieWindowDestroy();    
  110. }
  111.  
  112.  
  113. BOOL CSimplePlayerMFCView::OpenMovie(void)
  114. {
  115.     return pQuickTime->OpenMovie((unsigned char *)(LPCSTR)mfullPath);
  116. }
  117.  
  118. void CSimplePlayerMFCView::CloseMovie(void)
  119. {
  120.     CSimplePlayerMFCDoc* pDoc = GetDocument();
  121.  
  122.     pQuickTime->CloseMovie();
  123.  
  124.     pDoc->SetPathName( "Untitled", false );
  125. }
  126.  
  127. LRESULT CSimplePlayerMFCView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  128. {
  129.     if(message == WM_ERASEBKGND){
  130.         LRESULT theResult = CView::WindowProc(message, wParam, lParam);
  131.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);    
  132.         return theResult;
  133.     } else {
  134.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);
  135.         return CView::WindowProc(message, wParam, lParam);
  136.     }
  137. }
  138.  
  139. void CSimplePlayerMFCView::OnSize(UINT nType, int cx, int cy) 
  140. {
  141.     CView::OnSize(nType, cx, cy);
  142.     
  143.     if (cy && cx)
  144.     {
  145.         // calculate the size of the frame
  146.         CFrameWnd* pFrame = GetParentFrame();
  147.         if (pFrame != NULL)
  148.         {
  149.             CRect rectSized(0, 0, cx, cy);
  150.             pFrame->CalcWindowRect(rectSized);
  151.             pFrame->SetWindowPos(this,0,0,rectSized.Width() + 4,rectSized.Height()+ GetSystemMetrics(SM_CYMENU) + 4, SWP_NOZORDER | SWP_NOMOVE );
  152.  
  153.         }
  154.     }
  155.     
  156. }
  157.